package com.mobdev.notepadgdocs;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;

import com.mobdev.notepad.shared.ui.AbstractNotesList;
import com.mobdev.notepadgdocs.sync.SyncActivity;

/**
 * Displays a list of notes. Will display notes from the {@link Uri}
 * provided in the intent if there is one, otherwise defaults to displaying the
 * contents of the {@link NotepadProvider}
 */
public class NotesListGDocs extends AbstractNotesList {

    @Override
    protected void init() {


        /*
         * Load the default values so they're set even if the user does not go into the preferences
         * screen.
         */
        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);


        // If no data was given in the intent (because we were started
        // as a MAIN activity), then use our default content provider.
        Intent intent = getIntent();
        if (intent.getData() == null) {
            intent.setData(NotepadProvider.NOTEPAD_URI);
        }

        updateList();

        setContentView(R.layout.noteslist);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);


    	//AdManager.setTestDevices( new String[] {
    	//	      AdManager.TEST_EMULATOR, // Android emulator
    	//	      "5798A7A9FFD86C10ECF6F461E4877B9D"
    	//});
    }

	@Override
	protected int getNotesListItemId()
	{
		return R.layout.noteslist_item;
	}

	@Override
	protected int getSyncMenuIconId()
	{
		return R.drawable.sync_48;
	}

	@Override
	protected void doEditTitle(Uri mUri)
	{
		startActivity(new Intent(this, TitleEditor.class).setData(mUri));
	}


	@Override
	protected void doEditNote(Uri mUri, String action)
	{
		startActivity(new Intent(this, NoteEditor.class).setData(mUri).setAction(action));
	}

	@Override
	protected void doSync()
	{
    	//AdView adView = (AdView) findViewById(R.id.ad);
    	//adView.requestFreshAd();

		// Launch activity to sync notes with helipad
		startActivity(new Intent(this, SyncActivity.class));
	}

	@Override
	protected void doPreferences()
	{
		startActivityForResult(new Intent(this, PreferencesActivity.class), REQUEST_CODE_PREFERENCES );
	}

	@Override
	protected String getLocalyticsAppKey() {

		return NotepadProvider.LOCALYTICS_APP_KEY;  // Key generated on the webservice
	}
}
